package test.enba.security.auth.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.enba.boot.security.service.JwtUserService;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import test.enba.security.auth.entity.User;
import test.enba.security.auth.mapper.UserMapper;
import test.enba.security.auth.service.IUserService;

/** 用户表 服务实现类 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements IUserService, JwtUserService {

  @Override
  public User getUserByUsername(String username) {
    return getBaseMapper().selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername, username));
  }

  @Override
  public List<String> getRoleList(Long userId) {
    // FIXME 这里简单演示写死角色信息，实际开发中需要根据用户ID关联用户角色表，角色权限表从数据库中查询
    return new ArrayList<String>() {
      {
        add("admin");
      }
    };
  }

  @Override
  public List<String> getPermissionList(Long userId) {
    // FIXME 这里简单演示写死权限信息，实际开发中需要根据用户ID关联用户角色表，角色权限表从数据库中查询
    return new ArrayList<String>() {
      {
        add("order:insert");
        add("order:delete");
        add("order:select");
        add("user:findOne");
      }
    };
  }
}
